package com.ruoyi.system.mapper;

import java.util.List;
import java.util.Map;

import com.ruoyi.system.domain.InvoiceRecords;
import com.ruoyi.system.domain.ProductInfo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 产品明细Mapper接口
 * 
 * @author ruoyi
 * @date 2024-07-10
 */
public interface ProductInfoMapper 
{
    /**
     * 查询产品明细
     * 
     * @param id 产品明细主键
     * @return 产品明细
     */
    public ProductInfo selectProductInfoById(Long id);

    /**
     * 查询产品明细列表
     * 
     * @param productInfo 产品明细
     * @return 产品明细集合
     */
    public List<ProductInfo> selectProductInfoList(ProductInfo productInfo);

    /**
     * 新增产品明细
     * 
     * @param productInfo 产品明细
     * @return 结果
     */
    public int insertProductInfo(ProductInfo productInfo);

    /**
     * 修改产品明细
     * 
     * @param productInfo 产品明细
     * @return 结果
     */
    public int updateProductInfo(ProductInfo productInfo);

    /**
     * 删除产品明细
     * 
     * @param id 产品明细主键
     * @return 结果
     */
    public int deleteProductInfoById(Long id);

    /**
     * 批量删除产品明细
     * 
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteProductInfoByIds(Long[] ids);


    @Select("select distinct(i.product_code), model, specs, product_name, product_brand, provide, settlement_mode, g.product_group,plarn_price,product_price\n" +
            "from invoice_records i,invoice_group g\n" +
            "where provide != '物资中心库' and i.product_code = g.product_code\n" +
            "union\n" +
            "select distinct(r.product_code), model, specs, product_name, product_brand, provide, settlement_mode, g.product_group,plarn_price,product_price\n" +
            "from provide_records r,invoice_group g\n" +
            "where provide != '物资中心库' and r.product_code = g.product_code\n" +
            "union\n" +
            "select distinct(a.product_code), model, specs, product_name, product_brand, provide, settlement_mode, g.product_group,plarn_price,product_price\n" +
            "from invoice_records_audit a,invoice_group g\n" +
            "where provide != '物资中心库' and a.product_code = g.product_code")
    public List<Map<String,Object>> selectAllInvoiceRecords();


    @Select("\t\tSELECT DISTINCT\n" +
            "    i.product_code,\n" +
            "    model,\n" +
            "    specs,\n" +
            "    product_name,\n" +
            "    product_brand,\n" +
            "    provide,\n" +
            "    settlement_mode,\n" +
            "    g.product_group,\n" +
            "    plarn_price,\n" +
            "    product_price\n" +
            "FROM\n" +
            "    invoice_records i\n" +
            "    JOIN invoice_group g ON i.product_code = g.product_code\n" +
            "WHERE\n" +
            "    provide != '物资中心库'\n" +
            "    AND i.product_code NOT IN (SELECT DISTINCT(product_code) FROM product_info)\n" +
            "\t\t\n" +
            "\t\t\n" +
            "\t\t\n" +
            "\t\t\n" +
            "\n" +
            "UNION\n" +
            "\n" +
            "SELECT DISTINCT\n" +
            "    r.product_code,\n" +
            "    model,\n" +
            "    specs,\n" +
            "    product_name,\n" +
            "    product_brand,\n" +
            "    provide,\n" +
            "    settlement_mode,\n" +
            "    g.product_group,\n" +
            "    plarn_price,\n" +
            "    product_price\n" +
            "FROM\n" +
            "    provide_records r\n" +
            "    JOIN invoice_group g ON r.product_code = g.product_code\n" +
            "WHERE\n" +
            "    provide != '物资中心库'\n" +
            "    AND r.product_code NOT IN (SELECT DISTINCT(product_code) FROM product_info)\n" +
            "\n" +
            "UNION\n" +
            "\n" +
            "SELECT DISTINCT\n" +
            "    a.product_code,\n" +
            "    model,\n" +
            "    specs,\n" +
            "    product_name,\n" +
            "    product_brand,\n" +
            "    provide,\n" +
            "    settlement_mode,\n" +
            "    g.product_group,\n" +
            "    plarn_price,\n" +
            "    product_price\n" +
            "FROM\n" +
            "    invoice_records_audit a\n" +
            "    JOIN invoice_group g ON a.product_code = g.product_code\n" +
            "WHERE\n" +
            "    provide != '物资中心库'\n" +
            "    AND a.product_code NOT IN (SELECT DISTINCT(product_code) FROM product_info);")
    public List<Map<String,Object>> insertProductInfoS();

    @Select("select a.*,g.product_group from invoice_records_audit a,invoice_group g where a.product_code = g.product_code ")
    public List<Map<String,Object>> selectAllAudits();

    @Select("select r.*,g.product_group from provide_records r,invoice_group g where r.product_code = g.product_code  ")
    public List<Map<String,Object>> selectAllProvideRecors();


    @Select("select m.start_in_money,m.start_out_money,m.id from product_info i,product_money m where i.product_code = m.product_code " +
            "and m.status = '1' and i.product_code = #{productCode}")
    public Map<String,Object> selectProductMoney(@Param("productCode")String productCode,@Param("startInMoney")String startInMoney,@Param("startOutMoney")String startOutMoney);
}
